package com.wpf.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wpf.system.entity.RoleMenu;
import com.wpf.system.service.RoleMenuService;
import com.wpf.system.mapper.RoleMenuMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ferna
* @description 针对表【role_menu(角色关联权限表)】的数据库操作Service实现
* @createDate 2022-12-15 22:31:16
*/
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService{

    @Override
    public int saveRoleMenu(Long rid, List<Long> midList) {
        // 删除原有权限
        this.baseMapper.delete(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRid,rid));
        if (midList.size()>0){
            return this.baseMapper.saveRoleMenu(rid,midList);
        }else{
            return 1;
        }
    }

    @Override
    public int deleteRoleMenuByMid(List<Long> midList) {
        return this.baseMapper.deleteRoleMenuByMid(midList);
    }

    @Override
    public int deleteRoleMenuByRid(Long rid) {
        QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(RoleMenu::getRid,rid);
        return this.baseMapper.delete(queryWrapper);
    }
}




